package com.gnizr.snewsr;
import com.gnizr.core.bookmark.BookmarkManager;
import com.gnizr.core.link.LinkManager;
import com.gnizr.db.dao.GnizrDao;
import com.gnizr.db.dao.User;
import com.gnizr.db.dao.comment.*;
import com.gnizr.db.dao.Comment;
import com.gnizr.db.dao.Bookmark;
import com.gnizr.web.action.AbstractAction;
import com.gnizr.web.action.LoggedInUserAware;

import java.util.Date;

public class AddCommentAction extends AbstractAction implements LoggedInUserAware {
	  
	  private static final long serialVersionUID = 8604179423988890376L;

	// input from the client
	  private int bookmarkId;
		
	  private String message;
	  private String date;
	  private GnizrDao gnizrdao; 
	  private User loggedInUser;
	  private String comment;
	  private CommentDao commentDao;
	  private Comment cmt;
	  private Bookmark bookmark;
	  
	  private int newId;
	  private BookmarkManager bookmarkManager;
	  
	  public String getComment() {
		return comment;
	}


	public void setComment(String comment) {
		this.comment = comment;
	}

	public User getLoggedInUser() {
		return loggedInUser;
	}


	public GnizrDao getGnizrdao() {
		return gnizrdao;
	}


	public void setGnizrdao(GnizrDao gnizrdao) {
		this.gnizrdao = gnizrdao;
	}


	public String getDate() {
		   Date datenow = new Date();
		   date = datenow.toString();
		   return date;
	  }
	  
	        
	  public String getMessage() {
	    return message;
	  }
	  public void setMessage(String message) {
	    this.message = message;
	  }

	  @Override
	  protected String go() throws Exception {
		if(comment != null && getBookmarkId() > 0) {
			bookmark = bookmarkManager.getBookmark(getBookmarkId());
			cmt = new Comment(loggedInUser, bookmark.getId());
			cmt.setText(comment);
			cmt.setRank(5);
			cmt.setLastUpdated(new Date());
			cmt.setCreatedOn(new Date());
			newId = commentDao.createComment(this.cmt);
			
		}
	    return SUCCESS;
	  }


	public void setLoggedInUser(User loggedInUser) {
		this.loggedInUser = loggedInUser;
	}


	public int getBookmarkId() {
		return bookmarkId;
	}


	public void setBookmarkId(int bookmarkId) {
		this.bookmarkId = bookmarkId;
	}


	public Comment getCmt() {
		return cmt;
	}


	public void setCmt(Comment cmt) {
		this.cmt = cmt;
	}


	public Bookmark getBookmark() {
		return bookmark;
	}


	public void setBookmark(Bookmark bookmark) {
		this.bookmark = bookmark;
	}


	public int getNewId() {
		return newId;
	}


	public void setNewId(int newId) {
		this.newId = newId;
	}


	public BookmarkManager getBookmarkManager() {
		return bookmarkManager;
	}


	public void setBookmarkManager(BookmarkManager bookmarkManager) {
		this.bookmarkManager = bookmarkManager;
	}


	public CommentDao getCommentDao() {
		return commentDao;
	}


	public void setCommentDao(CommentDao commentDao) {
		this.commentDao = commentDao;
	}
	}
